home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / PGC122 / PREAPP.PAS < prev    next >
Pascal/Delphi Source File  |  1994-02-09  |  9KB  |  387 lines

  1. { Created : 1991-09-05
  2.  
  3. Functions and procedures used by the PtGen created application
  4.  
  5. $Author: Berend_de_Boer $
  6. $Date: 93/05/20 23:00:55 $
  7. $Revision: 1.1 $
  8.  
  9. Last changes :
  10. 93-02-01  Made completely TV2.0 aware
  11. 93-03-06  Renamed to PREAPP.PAS
  12.           Internationalized by making use of string resources
  13. 93-12-21  Added support for the Clock and HeapViewer from the Gadgets unit in
  14.           /bp/examples/dos/tvdemo
  15. }
  16.  
  17. {$I DEFINES.DEF}
  18.  
  19. {$F+,O+,X+,R-,Q-,S-,V-,D+}
  20. unit PreApp;
  21.  
  22. interface
  23.  
  24. uses Objects, Drivers, Views, Menus,
  25.      {$IFDEF Editor}
  26.      Editors,
  27.      {$ENDIF}
  28.      {$IFDEF TVTool}         {* you can only compile PreApp when TVTool *}
  29.      TVApp,                  {* is defined in DEFINES.DEF when you have *}
  30.      {$ENDIF}                {* the TVTool pack of Richard Hansen       *}
  31.      {$IFDEF Clock}
  32.      Gadgets,
  33.      {$ELSE}
  34.      {$IFDEF HeapViewer}
  35.      Gadgets,
  36.      {$ENDIF}
  37.      {$ENDIF}
  38.      App;
  39.  
  40.  
  41. {$IFDEF Editor}
  42. const
  43.   hcEditor = 2700;
  44. {$ENDIF}
  45.  
  46. type
  47.   PPreAppStatusLine = ^TPreAppStatusLine;
  48.   TPreAppStatusLine = object(TStatusLine)
  49.     function Hint(AHelpCtx : word) : string;  virtual;
  50.   end;
  51.  
  52.   PPreApp = ^TPreApp;
  53. {$IFDEF TVTool}
  54.   TPreApp = object(TbxApplication)
  55. {$ELSE}
  56.   TPreApp = object(TApplication)
  57. {$ENDIF}
  58. {$IFDEF Clock}
  59.     Clock : PClockView;
  60. {$ENDIF}
  61. {$IFDEF HeapViewer}
  62.     Heap : PHeapView;
  63. {$ENDIF}
  64.     constructor Init;
  65. {$IFDEF BufferedPrinter}
  66.     procedure Idle;  virtual;
  67. {$ELSE}
  68. {$IFDEF Clock}
  69.     procedure Idle;  virtual;
  70. {$ELSE}
  71. {$IFDEF HeapViewer}
  72.     procedure Idle;  virtual;
  73. {$ENDIF}
  74. {$ENDIF}
  75. {$ENDIF}
  76. {$IFDEF Help}
  77.     procedure GetEvent(var Event : TEvent);  virtual;
  78. {$IFNDEF TVTool}
  79.     function  GetPalette : PPalette;  virtual;
  80. {$ENDIF TVTool}
  81. {$ENDIF Help}
  82.     procedure OutOfMemory;  virtual;
  83.   end;
  84.  
  85. {$IFDEF Help}
  86. var
  87.   HFileName : FNameStr;
  88. {$ENDIF}
  89.  
  90. {$IFDEF Editor}
  91. var
  92.   ClipWindow : PEditWindow;
  93.  
  94. function OpenEditor(FileName: FNameStr; Visible: Boolean) : PEditWindow;
  95. {$ENDIF}
  96.  
  97.  
  98. implementation
  99.  
  100. uses Dialogs,
  101.      {$IFDEF Editor}
  102.      StdDlg,
  103.      {$ENDIF}
  104.      {$IFDEF Help}
  105.      HelpFile,
  106.      {$ENDIF}
  107.      {$IFDEF BufferedPrinter}
  108.      BufPrinter,
  109.      {$ENDIF}
  110.      Dos, BBFile, BBUtil, BBDlg, BBStrRes;
  111.  
  112.  
  113. {$I STRINGS.INC}
  114.  
  115.  
  116. function TPreAppStatusLine.Hint(AHelpCtx : word) : string;
  117. begin
  118.   Hint := Strings^.Get(AHelpCtx);
  119. end;
  120.  
  121.  
  122. {$IFDEF Editor}
  123. function CreateFindDialog: PDialog;
  124. var
  125.   D: PDialog;
  126.   Control: PView;
  127.   R: TRect;
  128. begin
  129.   R.Assign(0, 0, 38, 12);
  130.   D := New(PDialog, Init(R, rsGet(seFind)));
  131.   with D^ do
  132.   begin
  133.     Options := Options or ofCentered;
  134.  
  135.     R.Assign(3, 3, 32, 4);
  136.     Control := New(PInputLine, Init(R, 80));
  137.     Insert(Control);
  138.     R.Assign(2, 2, 15, 3);
  139.     Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
  140.     R.Assign(32, 3, 35, 4);
  141.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  142.  
  143.     R.Assign(3, 5, 35, 7);
  144.     Insert(New(PCheckBoxes, Init(R,
  145.       NewSItem(rsGet(seCase),
  146.       NewSItem(rsGet(seWholeWords), nil)))));
  147.  
  148.     R.Assign(14, 9, 24, 11);
  149.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  150.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  151.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  152.  
  153.     SelectNext(False);
  154.   end;
  155.   CreateFindDialog := D;
  156. end;
  157.  
  158.  
  159. function CreateReplaceDialog: PDialog;
  160. var
  161.   D: PDialog;
  162.   Control: PView;
  163.   R: TRect;
  164. begin
  165.   R.Assign(0, 0, 40, 16);
  166.   D := New(PDialog, Init(R, rsGet(seReplace)));
  167.   with D^ do
  168.   begin
  169.     Options := Options or ofCentered;
  170.  
  171.     R.Assign(3, 3, 34, 4);
  172.     Control := New(PInputLine, Init(R, 80));
  173.     Insert(Control);
  174.     R.Assign(2, 2, 15, 3);
  175.     Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
  176.     R.Assign(34, 3, 37, 4);
  177.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  178.  
  179.     R.Assign(3, 6, 34, 7);
  180.     Control := New(PInputLine, Init(R, 80));
  181.     Insert(Control);
  182.     R.Assign(2, 5, 12, 6);
  183.     Insert(New(PLabel, Init(R, rsGet(seNewText), Control)));
  184.     R.Assign(34, 6, 37, 7);
  185.     Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
  186.  
  187.     R.Assign(3, 8, 37, 12);
  188.     Insert(New(PCheckBoxes, Init(R,
  189.       NewSItem(rsGet(seCase),
  190.       NewSItem(rsGet(seWholeWords),
  191.       NewSItem(rsGet(sePromptOnReplace),
  192.       NewSItem(rsGet(seReplaceAll), nil)))))));
  193.  
  194.     R.Assign(17, 13, 27, 15);
  195.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  196.     R.Assign(28, 13, 38, 15);
  197.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  198.  
  199.     SelectNext(False);
  200.   end;
  201.   CreateReplaceDialog := D;
  202. end;
  203.  
  204.  
  205. function DoEditDialog(Dialog: Integer; Info: Pointer): Word; far;
  206. var
  207.   R: TRect;
  208.   T: TPoint;
  209. begin
  210.   case Dialog of
  211.     edOutOfMemory:
  212.       DoEditDialog := MessageBox(rsGet(sMemory),
  213.         nil, mfError + mfOkButton, hcNoContext);
  214.     edReadError:
  215.       DoEditDialog := MessageBox(rsGet(seErrReading),
  216.         @Info, mfError + mfOkButton, hcNoContext);
  217.     edWriteError:
  218.       DoEditDialog := MessageBox(rsGet(seErrWriting),
  219.         @Info, mfError + mfOkButton, hcNoContext);
  220.     edCreateError:
  221.       DoEditDialog := MessageBox(rsGet(seErrCreating),
  222.         @Info, mfError + mfOkButton, hcNoContext);
  223.     edSaveModify:
  224.       DoEditDialog := MessageBox(rsGet(seSave),
  225.         @Info, mfInformation + mfYesNoCancel, hcNoContext);
  226.     edSaveUntitled:
  227.       DoEditDialog := MessageBox(rsGet(seSaveUntitled),
  228.         nil, mfInformation + mfYesNoCancel, hcNoContext);
  229.     edSaveAs:
  230.       DoEditDialog := ExecDialog(New(PFileDialog, Init('*.*',
  231.         rsGet(seSaveAs), rsGet(sName), fdOkButton, 101)), Info);
  232.     edFind:
  233.       DoEditDialog := ExecDialog(CreateFindDialog, Info);
  234.     edSearchFailed:
  235.       DoEditDialog := MessageBox(rsGet(seStringNotFound),
  236.         nil, mfError + mfOkButton, hcNoContext);
  237.     edReplace:
  238.       DoEditDialog := ExecDialog(CreateReplaceDialog, Info);
  239.     edReplacePrompt:
  240.       begin
  241.         { Avoid placing the dialog on the same line as the cursor }
  242.         R.Assign(0, 1, 40, 8);
  243.         R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  244.         Desktop^.MakeGlobal(R.B, T);
  245.         Inc(T.Y);
  246.         if TPoint(Info).Y <= T.Y then
  247.           R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  248.         DoEditDialog := MessageBoxRect(R, rsGet(seReplaceThis),
  249.           nil, mfYesNoCancel + mfInformation, hcNoContext);
  250.       end;
  251.   end;
  252. end;
  253.  
  254.  
  255. function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
  256. var
  257.   P: PView;
  258.   R: TRect;
  259. begin
  260.   DeskTop^.GetExtent(R);
  261.   P := Application^.ValidView(New(PEditWindow,
  262.     Init(R, FileName, wnNoNumber)));
  263.   P^.HelpCtx := hcEditor;
  264.   if not Visible then P^.Hide;
  265.   DeskTop^.Insert(P);
  266.   OpenEditor := PEditWindow(P);
  267. end;
  268. {$ENDIF}
  269.  
  270. constructor TPreApp.Init;
  271. var
  272.   R : TRect;
  273. begin
  274.   if Strings = nil then  begin
  275.     PrintStr('You should load the resource strings first using BBStrRes.LoadStrings. Program halts.');
  276.     Halt(1);
  277.   end;
  278.   inherited Init;
  279.  
  280. {$IFDEF Clock}
  281.   GetExtent(R);
  282.   R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
  283.   Clock := New(PClockView, Init(R));
  284.   Insert(Clock);
  285. {$ENDIF}
  286.  
  287. {$IFDEF HeapViewer}
  288.   GetExtent(R);
  289.   Dec(R.B.X);
  290.   R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
  291.   Heap := New(PHeapView, Init(R));
  292.   Insert(Heap);
  293. {$ENDIF}
  294.  
  295. {$IFDEF Editor}
  296.   DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
  297.     cmUndo, cmFind, cmReplace, cmSearchAgain]);
  298.   EditorDialog := DoEditDialog;
  299.   ClipWindow := OpenEditor('', False);
  300.   if ClipWindow <> nil then
  301.   begin
  302.     Clipboard := ClipWindow^.Editor;
  303.     Clipboard^.CanUndo := False;
  304.   end;
  305. {$ENDIF}
  306.  
  307. end;
  308.  
  309.  
  310. {$IFDEF Help}
  311. procedure TPreApp.GetEvent(var Event : TEvent);
  312. var
  313.   W : PWindow;
  314.   HFile : PHelpFile;
  315.   HelpStrm : PBufStream;
  316.   D : DirStr;
  317.   N : NameStr;
  318.   E : ExtStr;
  319.   FileName : string;
  320. const
  321.   HelpInUse: Boolean = False;
  322. begin
  323.   inherited GetEvent(Event);
  324.   case Event.What of
  325.     evCommand : if (Event.Command = cmHelp) and not HelpInUse then  begin
  326.         HelpInUse := TRUE;
  327.         FSplit(ParamStr(0), D,N,E);
  328.         FileName := FSearch(HFileName, D+';'+';'+GetEnv('PATH'));
  329.         if FileName = ''
  330.          then  PrintError(rsGet1(sHelpFileNotFound, longint(@HFileName)), hcNoContext)
  331.          else  ShowHelpWindow(FileName, GetHelpCtx);
  332.         ClearEvent(Event);
  333.         HelpInUse := FALSE;
  334.       end;
  335.   end; { of case }
  336. end;
  337.  
  338. {$IFNDEF TVTool}
  339. function TPreApp.GetPalette: PPalette;
  340. const
  341.   CNewColor = CAppColor + CHelpColor;
  342.   CNewBlackWhite = CAppBlackWhite + CHelpBlackWhite;
  343.   CNewMonochrome = CAppMonochrome + CHelpMonochrome;
  344.   P: array[apColor..apMonochrome] of string[Length(CNewColor)] =
  345.     (CNewColor, CNewBlackWhite, CNewMonochrome);
  346. begin
  347.   GetPalette := @P[AppPalette];
  348. end;
  349. {$ENDIF TVTool}
  350. {$ENDIF Help}
  351.  
  352.  
  353. {$IFDEF BufferedPrinter}
  354. procedure TPreApp.Idle;
  355. begin
  356.   inherited Idle;
  357.   if StandardPrinter <> nil then  StandardPrinter^.PrintFromBuffer;
  358. end;
  359. {$ENDIF}
  360. {$IFDEF Clock}
  361. procedure TPreApp.Idle;
  362. begin
  363.   inherited Idle;
  364.   Clock^.Update;
  365. {$IFDEF HeapViewer}
  366.   Heap^.Update;
  367. {$ENDIF}
  368. end;
  369. {$ELSE}
  370. {$IFDEF HeapViewer}
  371. procedure TPreApp.Idle;
  372. begin
  373.   inherited Idle;
  374.   Heap^.Update;
  375. end;
  376. {$ENDIF}
  377. {$ENDIF}
  378.  
  379.  
  380. procedure TPreApp.OutOfMemory;
  381. begin
  382.   PrintError(rsGet(sMemory), hcNoContext);
  383. end;
  384.  
  385.  
  386. end.  { of unit PreApp }
  387.